package com.spring.boot.springBoot.utils.commonly;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by pactera on 2017/2/6.
 */
@Component
public class UrlValidator {
    public  static final String URL_PATTERN;
    static {
        URL_PATTERN = "(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])+([\\u4E00-\\u9FFF]+)?";
    }

    public boolean validate(final String name){
        Pattern pattern =  Pattern.compile(URL_PATTERN);
        Matcher matcher = pattern.matcher(name);
        return matcher.matches();
    }

//    public static void main(String[] args) throws Exception {
//        Pattern pattern =  Pattern.compile(URL_PATTERN);
//        Matcher matcher = pattern.matcher("http://172.16.2.204:81/#/innovation-list/once/jjj?activity=qwew我阿斯达所大所");
//
//        System.out.print(matcher.matches());
//    }
}
